import Vue from 'vue';
import VueRouter from 'vue-router';



import Layout from '@/views/dashboard/Layout'
import HomeLayout from '@/views/home/HomeLayout'

import HomeIndex from '../views/home/Index'
import AdminIndex from '../views/dashboard/Index'
import Chat from '../views/dashboard/Chat'
import ChatRoom from '../views/dashboard/ChatRoom'
import Moment from '../views/dashboard/Moment'
import UserMoment from '../views/dashboard/UserMoment'

import Login from '../views/dashboard/Login'
import Regedit from '../views/dashboard/Regedit'


import Profile from '../views/dashboard/childComps/account/Profile'
import Password from '../views/dashboard/childComps/account/Password'
import Avatar from '../views/dashboard/childComps/account/Avatar'
import UserList from '../views/dashboard/childComps/account/UserList'
import UserAdd from '../views/dashboard/childComps/account/UserAdd'

import UsersAdd from '../views/dashboard/childComps/users/UsersAdd'
import UsersModify from '../views/dashboard/childComps/users/UsersModify'
import UsersList from '../views/dashboard/childComps/users/UsersList'
import UsersQuery from '../views/home/childComps/users/UsersQuery'
import UsersDetail from '../views/home/childComps/users/UsersDetail'
import ChatmsgAdd from '../views/dashboard/childComps/chatmsg/ChatmsgAdd'
import ChatmsgModify from '../views/dashboard/childComps/chatmsg/ChatmsgModify'
import ChatmsgList from '../views/dashboard/childComps/chatmsg/ChatmsgList'
import ChatmsgQuery from '../views/home/childComps/chatmsg/ChatmsgQuery'
import ChatmsgDetail from '../views/home/childComps/chatmsg/ChatmsgDetail'
import ChatfileAdd from '../views/dashboard/childComps/chatfile/ChatfileAdd'
import ChatfileModify from '../views/dashboard/childComps/chatfile/ChatfileModify'
import ChatfileList from '../views/dashboard/childComps/chatfile/ChatfileList'
import ChatfileQuery from '../views/home/childComps/chatfile/ChatfileQuery'
import ChatfileDetail from '../views/home/childComps/chatfile/ChatfileDetail'

Vue.use(VueRouter)

const routes = [
    {
        path: '/',
        redirect: '/dashboard',
        component:HomeLayout,
        children:[
            { path:'/users-list',component:UsersQuery,meta:{title:'用户表列表'}},
{ path:'/users-detail/:id',component:UsersDetail,meta:{title:'用户表列表'}},
{ path:'/chatmsg-list',component:ChatmsgQuery,meta:{title:'聊天记录列表'}},
{ path:'/chatmsg-detail/:id',component:ChatmsgDetail,meta:{title:'聊天记录列表'}},
{ path:'/chatfile-list',component:ChatfileQuery,meta:{title:'聊天文件列表'}},
{ path:'/chatfile-detail/:id',component:ChatfileDetail,meta:{title:'聊天文件列表'}},

            {path: '/index',component: HomeIndex,meta:{title:'首页'}},
            { path: '/moment', component: Moment, meta:{title:'朋友圈'}}
        ]
    }, 
    {
        path: '/login',
        component: Login
    },
    {
        path: '/regedit',
        component: Regedit
    },
    {
        path: '/dashboard',
        component: Layout,
        redirect: '/dashboard/index',
        children: [
            { path:'users-add',component:UsersAdd,meta:{title:'用户表新增'}},
{ path:'users-edit/:id',component:UsersModify,meta:{title:'用户表修改'}},
{ path:'users-list',component:UsersList,meta:{title:'用户表列表'}},
{ path:'chatmsg-add',component:ChatmsgAdd,meta:{title:'聊天记录新增'}},
{ path:'chatmsg-edit/:id',component:ChatmsgModify,meta:{title:'聊天记录修改'}},
{ path:'chatmsg-list',component:ChatmsgList,meta:{title:'聊天记录列表'}},
{ path:'chatfile-add',component:ChatfileAdd,meta:{title:'聊天文件新增'}},
{ path:'chatfile-edit/:id',component:ChatfileModify,meta:{title:'聊天文件修改'}},
{ path:'chatfile-list',component:ChatfileList,meta:{title:'聊天文件列表'}},

            { path: 'user-add', component: UserAdd, meta: { title: '用户新增' } },
            { path: 'user-list', component: UserList, meta: { title: '用户列表' } },
            { path: 'avatar', component: Avatar, meta: { title: '上传头像' } },
            { path: 'password', component: Password, meta: { title: '密码设置' } },
            { path: 'profile', component: Profile, meta: { title: '资料修改' } },
            { path: 'moment', component: Moment, meta: { title: '朋友圈' } },
            { path: 'user-moment/:userId', component: UserMoment, meta: { title: '用户朋友圈' } },
            { path: 'index', component: AdminIndex, meta: { title: '聊天中心' } },
            { path: 'chat/:id', component: Chat, meta: { title: '聊天' } },
            { path: 'chatroom', component: ChatRoom, meta: { title: '公共聊天室' } },
        ]
    }
]

const router = new VueRouter({
   // mode: 'history',
    routes: routes
})


router.beforeEach((to, from, next) => {
    if (to.meta.title) {
        document.title = to.meta.title
    }
    if (to.path === '/login' || to.path === '/regedit') {
        next();
    } else {
        let token = window.localStorage.token;
        if (token === 'null' || token === '' || token === undefined) {
            next('/login')
        } else {
            next();
        }
    }
})

export default router